<template>
  <div>
    <van-nav-bar
      title="我的收藏"
      left-arrow
      @click-left="$router.back()"
    />
    <van-swipe-cell v-for="(item,index) in starList" :key="item.id">
      <hmArticleItem  :obj="item" @click.native="toPage(item.id)">
      </hmArticleItem>
      <template #right>
        <van-button square text="删除" type="danger" class="delete-button"  @click="unStar(item.id,index)"/>
      </template>
    </van-swipe-cell>
  </div>
</template>

<script>
import hmArticleItem from "@/components/hmArticleItem.vue";
import { user_star,post_star } from "@/apis/newsDetail";
export default {
  components: { hmArticleItem },
  created() {
    user_star().then((res) => {
      console.log(14, res);
      this.starList = res.data.data;
    });
  },
  data() {
    return {
      starList: [],
    };
  },
  methods: {
    unStar(id,index){
      post_star(id).then(res=>{
        console.log(37,res);
        this.starList.splice(index,1)
      })
    },
    toPage(id){
      this.$router.push({
        path:'/newsDetail',
        query:{
          id
        }
        })
    }
  },
};
</script>

<style lang="less" scoped>
.van-button--square{
  height: 100%;
}
</style>